#include "Tile.h"
#include "../SGD Wrappers/SGD_Message.h"

#include <cassert>
#include "../SGD Wrappers/SGD_GraphicsManager.h"
#include "TileSystem.h"

Tile::Tile ( SGD::Point loc, unsigned int tileID, unsigned int setID,
			int trigID, bool isPass)
{
	m_ptLoc					= loc;
	m_nTileID				= tileID;
	m_nSetID				= setID;
	m_nTriggerID			= trigID;
	m_bIsPassable			= isPass;
}

void Tile::Render( void )
{
	// if ( GameplayState::GetInstance ()->GetCameraRect ().IsIntersecting ( GetRect () ) == true )
	if(m_nSetID != -1)
	SGD::GraphicsManager::GetInstance()->DrawTextureSectionR(
		TILESYSTEM->GetTileSet(m_nSetID).m_hImage, TILESYSTEM->GetRenderPoint(m_ptLoc), 
		TILESYSTEM->GetSection(m_nTileID, m_nSetID));
}

int Tile::GetTrigger( void )
{
	return m_nTriggerID;
}

SGD::Rectangle Tile::GetRect( void )
{
	SGD::Rectangle rect;
	
	rect.left = m_ptLoc.x;
	rect.top = m_ptLoc.y;
	rect.right = rect.left + TILESYSTEM->GetTileSize().m_nWidth;
	rect.bottom = rect.top + TILESYSTEM->GetTileSize().m_nHeight;

	return rect;

}

bool Tile::IsPassable( void )
{
	return m_bIsPassable;
}